﻿namespace UserVoiceApi.Tests
{
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using Should;
    using Should.Fluent;

    [TestClass]
    public class SSOTests
    {
        [TestMethod]
        public void GenerateUserDetails_should_return_json_with_user_details()
        {
            var userDetails = GetDummyUserDetails();

            string userDetailsJson = SSO.CreateUserJson(userDetails);

            userDetailsJson.Should().Contain(userDetails.DisplayName);
            userDetailsJson.Should().Contain(userDetails.Admin);
            userDetailsJson.Should().Contain(userDetails.AvatarUrl);
            userDetailsJson.Should().Contain(userDetails.Expires);
            userDetailsJson.Should().Contain(userDetails.Guid);
            userDetailsJson.Should().Contain(userDetails.Url);
            userDetailsJson.Should().Contain(userDetails.AllowForums);
            userDetailsJson.Should().Contain(userDetails.DenyForums);
            userDetailsJson.Should().Contain(userDetails.Updates);
            userDetailsJson.Should().Contain(userDetails.CommentUpdates);
            userDetailsJson.Should().Contain(userDetails.Owner);
        }

        [TestMethod]
        public void CreateUserJson_should_return_encrypted_sso_token()
        {
            var userDetails = GetDummyUserDetails();
            string userDetailsJson = SSO.CreateUserJson(userDetails);

            string token = SSO.CreateToken("userinexperience", "ef97d9b4da4128ebe3202df908f9f40a", userDetailsJson);

            token.ShouldNotBeEmpty();
            token.ShouldNotContain("userinexperience");
            token.ShouldNotContain("ef97d9b4da4128ebe3202df908f9f40a");
            token.ShouldNotContain(userDetails.DisplayName);
        }

        private static UserDetails GetDummyUserDetails()
        {
            return new UserDetails
                        {
                            DisplayName = "Brandon Satrom",
                            Admin = "deny",
                            AvatarUrl = "http://www.gravatar.com/avatar/925d804db89a698c5e93b5f4c575d9a0.png",
                            Email = "bsatrom@gmail.com",
                            Expires = "11/11/2011",
                            Guid = "12344",
                            Url = "http://www.userinexperience.com",
                            AllowForums = "1234",
                            DenyForums = "2345",
                            Updates = "false",
                            CommentUpdates = "true",
                            Owner = "accept"
                        };
        }
    }
}
